package com.cdc.network.view;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.cdc.network.RequestType;

/**
 * Created by admin on 2018/4/14.
 */

public class RequestPagerAdapter extends FragmentPagerAdapter {

    private static final int PAGE_COUNT = 5;
    private Context mContext;
    @Override
    public Fragment getItem(int position) {
        RequestType type;
        String title;
        switch (position) {
            case 0:
                type = RequestType.GET;
                title=RequestType.GET.name();
                break;
            case 1:
                type = RequestType.POST;
                title=RequestType.POST.name();
                break;
            case 2:
                type = RequestType.POST_JSON;
                title=RequestType.POST_JSON.name();
                break;
            case 3:
                type = RequestType.UPLOAD;
                title=RequestType.UPLOAD.name();
                break;
            case 4:
                type = RequestType.UPLOADS;
                title=RequestType.UPLOADS.name();
                break;
            default:
                type = RequestType.GET;
                title=RequestType.GET.name();
                break;
        }
        return RequestFragment.newInstance(title,type);
    }

    @Override
    public int getCount() {
        return PAGE_COUNT;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return RequestType.GET.name();
            case 1:
                return RequestType.POST.name();
            case 2:
                return RequestType.POST_JSON.name();
            case 3:
                return RequestType.UPLOAD.name();
            case 4:
                return RequestType.UPLOADS.name();
            default:
                return RequestType.GET.name();
        }
    }


    public RequestPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public RequestPagerAdapter(Context context, FragmentManager fm){
        super(fm);
        this.mContext = context;
    }
}
